home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / system-tools / tinymeter / source / tinymeter_main / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-21  |  7.8 KB  |  300 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <dos/dosextens.h>
  5. #include <intuition/intuition.h>
  6. #include <intuition/gadgetclass.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <intuition/classusr.h>
  9. #include <intuition/gadgetclass.h>
  10. #include <intuition/cghooks.h>
  11. #include <intuition/icclass.h>
  12. #include <intuition/classes.h>
  13. #include <intuition/sghooks.h>
  14. #include <intuition/screens.h>
  15. #include <datatypes/datatypesclass.h>
  16. #include <datatypes/datatypes.h>
  17. #include <datatypes/pictureclass.h>
  18. #include <libraries/SysInfo.h>
  19. #include <libraries/gadtools.h>
  20. #include <graphics/gfxbase.h>
  21. #include <graphics/text.h>
  22. #include <graphics/gfxmacros.h>
  23. #include <utility/tagitem.h>
  24. #include <utility/hooks.h>
  25. #include <string.h>
  26. #include <clib/macros.h>
  27. #include "gaugeclass.h"
  28. #include "launchclass.h"
  29. #include "tinymeter.h"
  30.  
  31. extern struct Library *RetinaBase;
  32.  
  33. /* the only two globals */
  34.  
  35. extern ULONG    maximum,
  36.         idle;
  37.  
  38. drawBackground(struct tm_sys_set *set,struct tm_data *data)
  39. {
  40.     struct RastPort *rp=data->win->RPort;
  41.     UWORD  x,y;
  42.  
  43.     x=data->win->Width-1;
  44.     y=data->win->Height-1;
  45.  
  46.     if(data->bg_bm)
  47.     {
  48.     BltBitMapRastPort(data->bg_bm,0,0,rp,0,0,x+1,y+1,0xc0);
  49.     FreeBitMap(data->bg_bm); data->bg_bm=0L;
  50.     }
  51.     else
  52.     {
  53.     SetAPen(rp,data->bg_color);
  54.     RectFill(rp,0,0,x,y);
  55.     }
  56.  
  57.     SetAPen(rp,data->bright_color);
  58.     switch (set->bd_type)
  59.     {
  60.     case    bd_simple:
  61.         RectFill(rp,0,0,x,0);
  62.         RectFill(rp,0,0,0,y);
  63.         RectFill(rp,x,0,x,y);
  64.         RectFill(rp,0,y,x,y);
  65.         break;
  66.     case    bd_standard:
  67.         RectFill(rp,0,0,x,0);
  68.         RectFill(rp,0,0,0,y);
  69.         SetAPen(rp,data->dark_color);
  70.         RectFill(rp,x,1,x,y);
  71.         RectFill(rp,1,y,x,y);
  72.         break;
  73.     case    bd_double:
  74.         SetAPen(rp,data->dark_color);
  75.         RectFill(rp,0,0,x,0);
  76.         RectFill(rp,0,0,0,y);
  77.         RectFill(rp,1,y-1,x-1,y-1);
  78.         RectFill(rp,x-1,2,x-1,y-1);
  79.         SetAPen(rp,data->bright_color);
  80.         RectFill(rp,x,1,x,y);
  81.         RectFill(rp,1,y,x,y);
  82.         RectFill(rp,1,1,x-1,1);
  83.         RectFill(rp,1,1,1,y-1);
  84.         break;
  85.     }
  86. }
  87.  
  88. allocGadgets(struct tm_sys_set *set, struct tm_data *data, Class *gclass, Class *lclass)
  89. {
  90.     struct  tm_gau_set *many;
  91.     ULONG   i,max,cur,y_pos,j,tmp,voltype,x;
  92.     int     foo;
  93.     
  94.     for(i=0,many=data->list;i<data->num_of_gaug;i++)
  95.     {
  96.     voltype=0;
  97.     switch (many->type)
  98.     {
  99.         case    typ_all:
  100.             max=AvailMem(MEMF_TOTAL);
  101.             cur=AvailMem(0L);
  102.             foo=1;
  103.             break;
  104.         case    typ_chip:
  105.             max=AvailMem(MEMF_CHIP|MEMF_TOTAL);
  106.             cur=AvailMem(MEMF_CHIP);
  107.             foo=1;
  108.             break;
  109.         case    typ_fast:
  110.             max=AvailMem(MEMF_FAST|MEMF_TOTAL);
  111.             cur=AvailMem(MEMF_FAST);
  112.             foo=1;
  113.             break;
  114.         case    typ_largest_total:
  115.             max=AvailMem(MEMF_TOTAL);
  116.             cur=AvailMem(MEMF_LARGEST);
  117.             foo=1;
  118.             break;
  119.         case    typ_largest_chip:
  120.             max=AvailMem(MEMF_TOTAL|MEMF_CHIP);
  121.             cur=AvailMem(MEMF_LARGEST|MEMF_CHIP);
  122.             foo=1;
  123.             break;
  124.         case    typ_largest_fast:
  125.             max=AvailMem(MEMF_TOTAL|MEMF_FAST);
  126.             cur=AvailMem(MEMF_LARGEST|MEMF_FAST);
  127.             foo=1;
  128.             break;
  129.         case    typ_largest_retina:
  130.             if(RetinaBase)
  131.             {
  132.             max=Retina_AvailMem(MEMF_TOTAL);
  133.             cur=Retina_AvailMem(MEMF_LARGEST);
  134.             }
  135.             else
  136.             {
  137.             max=0L;
  138.             cur=GAU_err_notavail;
  139.             }
  140.             foo=1;
  141.             break;
  142.         case    typ_volume:
  143.             getVolsize(data,&many->expansion[0]);
  144.             max=data->volmax;
  145.             cur=data->volcur;
  146.             voltype=data->voltype;
  147.             foo=1;
  148.             break;
  149.         case    typ_idle:
  150.             switch (data->executive)
  151.             {
  152.             case    idle_none:
  153.                 max=0L;
  154.                 cur=GAU_err_notavail;
  155.                 break;
  156.             case    idle_executive:
  157.                 GetCpuUsage(data->si,&data->cpu);
  158.                 max=(data->cpu.used_cputime_lastsec_hz)<<8;
  159.                 cur=(data->cpu.used_cputime_lastsec_hz-data->cpu.used_cputime_lastsec)<<8;
  160.                 break;
  161.             case    idle_own:
  162.                 max=maximum;
  163.                 cur=idle;
  164.                 break;
  165.             }
  166.             foo=1;
  167.             break;
  168.         case    typ_retina:
  169.             if(RetinaBase)
  170.             {
  171.             max=Retina_AvailMem(MEMF_TOTAL);
  172.             cur=Retina_AvailMem(0L);
  173.             }
  174.             else
  175.             {
  176.             max=0L;
  177.             cur=GAU_err_notavail;
  178.             }
  179.             foo=1;
  180.             break;
  181.         case    typ_clock_:
  182.             many->gauge_type=typ_clock;
  183.             foo=1;
  184.             break;
  185.         case    typ_image:
  186.             foo=0;
  187.             break;
  188.         case    typ_none:
  189.             data->gdg[i]=0L;
  190.             foo=0;
  191.             break;
  192.         case    typ_simplelauncher:
  193.             foo=2;
  194.             break;
  195.     }
  196.     tmp=i/set->colums;
  197.     if(set->lay_falling)
  198.     {
  199.         y_pos=set->win_border_y+(tmp*set->win_space_y);
  200.         for(j=(i-(tmp*set->colums));j<i;j+=set->colums) y_pos+=data->gauge_y_size_falling[j];
  201.     }
  202.     else
  203.     {
  204.         y_pos= set->win_border_y+(tmp*set->win_space_y)+((data->gauge_y_size[tmp]-data->gauge_y_size_falling[i])>>1);
  205.         for(j=0;j<tmp;j++) y_pos+=data->gauge_y_size[j];
  206.     }
  207.     data->gauge_y_pos[i]=y_pos;
  208.     x=set->win_border_x+((i)%set->colums)*data->gauge_x_size+((i)%set->colums)*set->win_space_x;
  209.     switch (foo)
  210.     {
  211.         case    1 :  data->gdg[i]=(struct Gadget *)NewObject(gclass, NULL,
  212.                 GA_ID,              0xFFF4,
  213.                 GA_Top,             y_pos,
  214.                 GA_Left,            x,
  215.                 GA_Width,           data->gauge_x_size,
  216.                 GA_Height,          data->gauge_y_size_falling[i],
  217.                 GAU_Type,           many->gauge_type,
  218.                 GAU_Current,        cur,
  219.                 GAU_Max,            max,
  220.                 GAU_Base,           cur,
  221.                 GAU_VolType,        voltype,
  222.                 GAU_Label,          many->label,
  223.                 GAU_TextFormat,     many->format,
  224.                 GAU_TextFont,       data->Font[i],
  225.                 GAU_LabelPos,       data->labelpos,
  226.                 GAU_FmtIndent,      many->indent,
  227.  
  228.                 GAU_3D,             many->sty_3d,
  229.                 GAU_Border,         many->sty_border,
  230.                 GAU_Background,     many->sty_bg,
  231.                 GAU_ShadowLabel,    many->sty_shadow,
  232.                 GAU_NoGauge,        many->sty_nogauge,
  233.                 GAU_NoFormat,       many->sty_noformat,
  234.                 GAU_NoBase,         many->sty_nobase,
  235.  
  236.                 GAU_ColLabel,       &many->Colors[col_label],
  237.                 GAU_ColFormat,      &many->Colors[col_format],
  238.                 GAU_ColBase,        &many->Colors[col_base],
  239.                 GAU_ColCurrent,     &many->Colors[col_current],
  240.                 GAU_ColNegative,    &many->Colors[col_negative],
  241.                 GAU_ColBrightEdg,   &many->Colors[col_bright],
  242.                 GAU_ColDarkEdg,     &many->Colors[col_dark],
  243.                 GAU_ColBackground,  &many->Colors[col_bg],
  244.  
  245.                 TAG_END);
  246.             if(!data->gdg[i]) show(err_noboo);
  247.             else              AddGList(data->win,data->gdg[i],-1,1,NULL);
  248.             break;
  249.         case    2 :
  250.             data->gdg[i]=(struct Gadget *)NewObject(lclass, NULL,
  251.                 GA_ID,              i,
  252.                 GA_Top,             y_pos,
  253.                 GA_Left,            x,
  254.                 GA_Width,           data->gauge_x_size,
  255.                 GA_Height,          data->gauge_y_size_falling[i],
  256.                 GA_Immediate,       TRUE,
  257.                 GA_RelVerify,       TRUE,
  258.  
  259.                 LAU_File,           &many->expansion[0],
  260.                 LAU_TextFont,       data->Font[i],
  261.                 LAU_3D,             many->sty_3d,
  262.                 LAU_Border,         many->sty_border,
  263.                 LAU_Background,     many->sty_bg,
  264.                 LAU_ShadowLabel,    many->sty_shadow,
  265.                 LAU_Down,           many->sty_nogauge,
  266.                 LAU_Screen,         data->scr,
  267.                 LAU_Indent,         many->indent,
  268.  
  269.                 LAU_ColLabel,       &many->Colors[col_label],
  270.                 LAU_ColEntry,       &many->Colors[col_format],
  271.                 LAU_ColHalfBright,  &many->Colors[col_base],
  272.                 LAU_ColHalfShadow,  &many->Colors[col_current],
  273.                 LAU_ColCursor,      &many->Colors[col_negative],
  274.                 LAU_ColBrightEdg,   &many->Colors[col_bright],
  275.                 LAU_ColDarkEdg,     &many->Colors[col_dark],
  276.                 LAU_ColBackground,  &many->Colors[col_bg],
  277.                 TAG_END);
  278.             if(!data->gdg[i]) show(err_noboo);
  279.             else              AddGList(data->win,data->gdg[i],0,1,NULL);
  280.             break;
  281.  
  282.  
  283.     }
  284.     many=many->next;
  285.     }
  286.     RefreshGList(data->gdg[i],data->win,NULL,-1);
  287. }
  288.  
  289. removeGadgets(struct tm_sys_set *set, struct tm_data *data)
  290. {
  291.     int i;
  292.  
  293.     for(i=0;i<data->num_of_gaug;i++)
  294.     if(data->gdg[i])
  295.     {
  296.         DisposeObject(data->gdg[i]);
  297.         data->gdg[i]=0L;
  298.     }
  299. }
  300.